package cn.jia.websocket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;


/**
 * @Author: jia
 * @Descirption:
 * @Date: 2018/4/23 11:33
 * @Modified By:
 */


public class MarcoHandler extends TextWebSocketHandler{

    /**
     * @Author: jia
     * @Date: 2018/4/23 11:43
     * @Modified By: jia
     * @Descirption: 连接建立之后
     */
    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        super.afterConnectionEstablished(session);
    }

    /**
     * 处理消息
     * @param session
     * @param message
     * @throws Exception
     */
    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        System.out.println(message.getPayload());
        Thread.sleep(2000);
        session.sendMessage(new TextMessage("你好浏览器！"));
    }
    /**
     * @Author: jia
     * @Date: 2018/4/23 11:43
     * @Modified By: jia
     * @Descirption: 连接关闭之后
     */
    @Override
    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
        super.afterConnectionClosed(session, status);
    }



}
